package com.ydl.zhwc.mvpandrxjava.sample.mvp;

import com.ydl.zhwc.mvpandrxjava.bean.Now;
import com.ydl.zhwc.mvpandrxjava.sample.RxUtils;
import com.ydl.zhwc.mvpandrxjava.sample.http.ApiProvider;
import com.ydl.zhwc.mvpandrxjava.sample.http.ApiService;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/**
 * author : Zhangwenchao
 * e-mail : zhangwch@yidianling.com
 * time   : 2017/12/22
 */

public class MVPOldModel implements MVPContract.OldModel {

    @Override
    public void getNow(final Callback callback) {
        ApiProvider.getApiService()
                .rxWeather(ApiService.KEY, "hangzhou")
                .subscribeOn(Schedulers.io())
                .compose(RxUtils.handlerThrowable())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<Now>() {
                    @Override
                    public void accept(Now now) throws Exception {
                        callback.onSuccess(now);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        callback.onFail(RxUtils.getErrorMsg(throwable));
                    }
                });
    }

}
